// Example: public virtual void SetDescription(string value)
        private string BuildEvent(MethodInfo method, string ownerName)
        {
            if (!method.IsPublic)
            {
                throw new InvalidOperationException($"Event method \"{method.Name}\" should be public.");
            }
            if (!method.IsVirtual)
            {
                throw new InvalidOperationException($"Event method \"{method.Name}\" should be virtual.");
            }
            if (method.IsAbstract)
            {
                return(BuildAbstractEvent(method, ownerName));
            }
            if (method.ReturnType != typeof(void))
            {
                throw new InvalidOperationException($"Event method \"{method.Name}\" should return void.");
            }
            var paramsBuilder = new ParamsBuilder(method.GetParameters());

            GetEntityLoaders(method.DeclaringType).AppendLine(BuildEntityLoader(method.Name, paramsBuilder));
            return($@"
						public override void {method.Name}({paramsBuilder.CreateDeclarations()})
						{{
							if (!_loading)
							{{
								var @params = new Dictionary<string,object> {{{paramsBuilder.CreateDictionaryParams()}}};
								AddEvent(this, ""{method.Name}"", @params);
							}}
							base.{method.Name}({paramsBuilder.GetNameList()});
						}}"                        );
        }
        // Example: public abstract TestEntity CreateTestEntity(string name);
        private string BuildAbstractEvent(MethodInfo method, string ownerName)
        {
            if (!method.ReturnType.GetTypeInfo().IsClass)
            {
                throw new InvalidOperationException($"Event method \"{method.Name}\" should return class.");
            }
            var paramsBuilder = new ParamsBuilder(method.GetParameters());
            var sourceName    = method.ReturnType.Name;

            _entitiesCode.AppendLine(BuildEntityClass(method.ReturnType));
            _loaders.AppendLine(BuildLoader(method.ReturnType, method.Name, paramsBuilder));
            return($@"
						public override {method.ReturnType.ToCsDeclaration()} {method.Name}({paramsBuilder.CreateDeclarations()})
						{{
							if (_loading) throw new System.InvalidOperationException(""Invalid call in loading state."");
							var result = new {sourceName}Impl(_{ownerName}, {paramsBuilder.GetNameList()});
							var @params = new Dictionary<string,object> {{{paramsBuilder.CreateDictionaryParams()}}};
							AddEvent(result, ""{method.Name}"", @params);
							return result;
						}}"                        );
        }
Beispiel #3
0
        private string BuildCostructor(ConstructorInfo constructor, string ownerName)
        {
            var sourceName = _entityType.Name;
            var @params    = new ParamsBuilder(constructor.GetParameters());

            return($@"
								public {sourceName}Impl({_rootBuilder.TransactionType.Name} {ownerName}, {@params.CreateDeclarations()}) : base({@params.GetNameList()})
								{{
									_{ownerName} = {ownerName};
								}}"                                );
        }